package com.cetc;

/**
 * @Classname StaticProxyTest
 * @Description 静态代理举例
 * @Date 2022/12/13 20:48
 * @Created by louzhuangxi
 */
public class StaticProxyTest {
    public static void main(String[] args) {
        NikeClothFactory nikeClothFactory = new NikeClothFactory();
        AdidasClothFactory adidasClothFactory = new AdidasClothFactory();
        ProxyClothProxy proxyClothProxy1 = new ProxyClothProxy(nikeClothFactory);
        ProxyClothProxy proxyClothProxy2 = new ProxyClothProxy(adidasClothFactory);
        proxyClothProxy1.produceCloth();
        proxyClothProxy2.produceCloth();
    }
}

/**
 * 接口工厂
 */
interface ClothFactory {
    void produceCloth();
}

/**
 * 代理类
 */
class ProxyClothProxy implements ClothFactory {
    /**
     * 用被代理类对象进行实例化
     */
    private ClothFactory factory;

    public ProxyClothProxy(ClothFactory clothFactory) {
        this.factory = clothFactory;
    }

    @Override
    public void produceCloth() {
        System.out.println("代理工厂做一些准备工作");
        factory.produceCloth();
        System.out.println("代理工厂做一些收尾工作");
    }
}

/**
 * 被代理类Nike
 */
class NikeClothFactory implements ClothFactory {
    @Override
    public void produceCloth() {
        System.out.println("Nike 工厂生产一批运动服");
    }
}
/**
 * 被代理类adidas
 */
class AdidasClothFactory implements ClothFactory {
    @Override
    public void produceCloth() {
        System.out.println("Adidas 工厂生产一批运动服");
    }
}
